package com.ljw;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;

import javax.swing.JFrame;

public class MainFrameCanvasPhysicalEngine extends JFrame {

	public static void main(String[] args){
		MainFrameCanvasPhysicalEngine frame = new MainFrameCanvasPhysicalEngine();
		frame.run();
	}

	private void run() {
		this.init();
	}

	//초기화 메소드
	private void init() {
		//frame 설정
		this.setBounds(100, 100, 300, 300);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		
		//canvas 설정
		Canvas canvas = new Canvas();
		this.add(canvas);
		
		canvas.createBufferStrategy(2);
		BufferStrategy bs = canvas.getBufferStrategy();
		
		//그림그리기
		draw(bs);
	}

	//이미지 그리기
	private void draw(BufferStrategy bs) {
		Graphics g = null;
		
		Circle circle = new Circle(20, 20, 1d, 1d);
		
		while(true){
			g = bs.getDrawGraphics();
			g.clearRect(0, 0, 300, 300);
			
			//if(posX++ >= 300)
			circle.setX(circle.getX() + 1);	
			circle.setY(circle.getY() + 1);
			g.fillOval(circle.getX(), circle.getY(), 30, 30);
			
			if(!bs.contentsLost())bs.show();
		}
	}
	
}

class Circle{
	
	private	int	width;		//폭
	private	int	height;		//높이
	private	int	x;				//x축 위치
	private	int	y;				//y축 위치
	private double vx; 		//x축 가속도 
	private double vy;			//y축 가속도
	
	public Circle(int x, int y, double vx, double vy){
		width = 30;
		height = 30;
		this.x = x;
		this.y = y;
		this.vx = vx;
		this.vy = vy;
	}

	public int getWidth() {
		return width;
	}
	public void setWidth(int width) {
		this.width = width;
	}
	public int getHeight() {
		return height;
	}
	public void setHeight(int height) {
		this.height = height;
	}
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	public double getVx() {
		return vx;
	}
	public void setVx(double vx) {
		this.vx = vx;
	}
	public double getVy() {
		return vy;
	}
	public void setVy(double vy) {
		this.vy = vy;
	}
}